package com.yidu.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.yidu.domain.ListenBranchSell;
import com.yidu.domain.ListenBranchSellDetail;
import com.yidu.domain.ListenFinance;
import com.yidu.domain.ListenStock;

public interface ListenBranchSellMapper {
    int deleteByPrimaryKey(String bsId);

    int insert(ListenBranchSell record);

    int insertSelective(ListenBranchSell record);

    ListenBranchSell selectByPrimaryKey(String bsId);

    int updateByPrimaryKeySelective(ListenBranchSell record);

    int updateByPrimaryKey(ListenBranchSell record);

	List<ListenBranchSell> findAll(Map<String, Object> map);

	int findCount(Map<String, Object> map);

	int findByIdCount(Map<String, Object> map);

	@Select("select ls.stock_number from listen_stock ls where ls.mu_id=#{muId} AND ls.company_id=#{comId}")
	@ResultMap("BaseResultStockMap")
	List<ListenStock> findByMusicalNumber(@Param("muId")String muId,@Param("comId")String comId);

	List<ListenBranchSell> findMuId(String bsId);

	@Update("UPDATE listen_stock SET stock_number=stock_number-#{muNumber} WHERE mu_id=#{muId} AND company_id=#{site}")
	int reduceStock(@Param("muId")String muId,@Param("muNumber")Integer muNumber,@Param("site")String site);

	@Update("update listen_branch_sell set sort=2 where bs_id=#{bsId}")
	void updateSort(String bsId);
	
	@Update("UPDATE listen_finance SET company_price=company_price+#{sum} WHERE company_id=#{comId}")
	int updateMoney(@Param("comId")String comId,@Param("sum")Double sum);

	List<ListenBranchSell> findComId(String comId);
	
	@Select("SELECT * FROM listen_stock WHERE mu_id = #{muId} and company_id = #{comId}")
	@ResultMap("BaseResultStockMap")
	ListenStock findByStockId(@Param("muId")String muId,@Param("comId")String comId);

	List<ListenBranchSellDetail> findDetail(String bsId);

	@Select("SELECT finance_id FROM listen_branch_sell lbs,listen_company lc,listen_finance lf WHERE lbs.company_id = 	lc.company_id AND lf.company_id = lc.company_id AND lbs.bs_id = #{bsId}")
	@ResultMap("BaseResultFinanceMap")
	ListenFinance findCwId(String bsId);

	ListenBranchSell findAllByBsId(String bsId);

}